using System;
using System.Collections.Generic;
using System.IO;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using System.Drawing;
namespace Beauty {
	public class MenuSource : UITableViewSource {
		List<MenuItem> tableItems;
		 NSString cellIdentifier = new NSString("TableCell");
	
		public MenuSource (List<MenuItem> items)
		{
			tableItems = items;
		}
	
		/// <summary>
		/// Called by the TableView to determine how many cells to create for that particular section.
		/// </summary>
		public override int RowsInSection (UITableView tableview, int section)
		{
			return tableItems.Count;
		}
		
		/// <summary>
		/// Called when a row is touched
		/// </summary>
		public override void RowSelected (UITableView tableView, NSIndexPath indexPath)
		{
//			new UIAlertView("Row Selected"
//				, tableItems[indexPath.Row].Heading, null, "OK", null).Show();
//			tableView.DeselectRow (indexPath, true);
			 
		}
		
		/// <summary>
		/// Called by the TableView to get the actual UITableViewCell to render for the particular row
		/// </summary>
		public override UITableViewCell GetCell (UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath)
		{
			// request a recycled cell to save memory
			var	cell = tableView.DequeueReusableCell (cellIdentifier) as MenuCell;

			// if there are no cells to reuse, create a new one
			if (cell == null) {
				cell = new MenuCell (cellIdentifier);
			}
			var temp = new UIView (new RectangleF (0, 0, cell.Frame.Width, 80));
			var temp1 = new UIView (new RectangleF (0, 0, 5, 80));
			temp1.BackgroundColor = UIColorExtensions.FromHexString ("#ff485f");

			temp.Layer.BorderWidth = .5f;
			temp.Layer.BorderColor = UIColorExtensions.FromHexString ("#a7a7a7").CGColor;
			 
			temp.BackgroundColor = UIColorExtensions.FromHexString ("#efefef");
			temp.Add (temp1);
			cell.SelectedBackgroundView = temp;
			cell.UpdateCell (tableItems[indexPath.Row].Heading
							, tableItems[indexPath.Row].SubHeading
							, UIImage.FromFile ("Images/" +tableItems[indexPath.Row].ImageName) );
			
			return cell;
		}
	}
}